<template>
    <Switch v-model="task_current.task_enable" size="small" @on-change="handleTaskEnableChange(task_current)"></Switch>
</template>

<script>
export default {
    name: "TaskEnableSwitch",
    props: {
        data: Object,
    },
    data() {
        return {
            task_current: this.data
        }
    },
    methods: {
        handleTaskEnableChange(row) {
            this.$http.post('/task_enable', { task_id: row.task_id, task_enable: row.task_enable?1:0 }).then(res => {
                if (res.status == 'ok') {
                    this.$Message.success('切换成功');
                }else {
                    this.errorMessage('切换失败');
                    row.task_enable = !row.task_enable;
                }
            }).catch(() => {
                this.errorMessage('切换失败');
                row.task_enable = !row.task_enable;
            });
        },
    },
}
</script>